<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\admin\model\IndexModel;

class Index extends Common
{
	/**
	*	后台首页
	*/
	public function index()
	{
		$admin_id = Session::get('admin_id');
		if(!empty($admin_id)){
			$IndexModel = new IndexModel();
			$list = $IndexModel->getAdminUser($admin_id);
			if(!empty($list)){
		        $this->assign('list', $list);
			}
		}
		return $this->fetch('/index/index');
	}

	/**
	*	后台显示首页内容
	*/ 
	public function indexv1()
	{
		return $this->fetch('/index/index_v1');
	}

	/**
	*	修改密码
	*/
	public function editpass()
	{
		return $this->fetch('/index/editpass');
	}

	/**
	*	修改密码提交
	*/
	public function editPassPost()
	{

		if ($this->request->isPost()) {
			$admin_id = Session::get('admin_id');
			$data = $this->request->param();

			// 数据验证
			$result = $this->validate($data, 'EditPassValidate');

	        if ($result !== true) {
	            $this->error($result);
	        }

			$IndexModel = new IndexModel();
			$list = $IndexModel->editpassPost($admin_id,$data);

			if($list === 2){
				$this->error('原密码不正确');
			}elseif($list === 3){
				$this->error('新密码和确认密码不一致');
			}else{
				$this->success('修改成功');
			}
		}
	}
}